import java.util.Stack;

public class Test {

    public int evalRPN(String[] tokens) {
        Stack<Integer> stack = new Stack<>();
        for(String str : tokens){
            if(!isOperator(str)){
                int val = Integer.parseInt(str);
                stack.push(val);
            }else {
                int val2 = stack.pop();
                int val1 = stack.pop();
                switch (str){
                    case "+":
                        stack.push(val1+val2);
                        break;
                    case "-":
                        stack.push(val1-val2);
                        break;
                    case "*":
                        stack.push(val1*val2);
                        break;
                    case "/":
                        stack.push(val1/val2);
                        break;
                }
            }
        }
        return stack.peek();
    }

    private boolean isOperator(String str){
        if(str.equals("+") ||str.equals("-") ||
                str.equals("*") ||str.equals("/")){
            return true;
        }
        return false;
    }

    public boolean IsPopOrder (int[] pushV, int[] popV) {
        // write code here
        Stack<Integer> stack = new Stack<>();
        int j = 0;

        for (int i = 0; i < pushV.length; i++) {
            stack.push(pushV[i]);
            while (!stack.isEmpty() && j < popV.length && stack.peek() == popV[j] ){
                stack.pop();
                j++;
            }

        }
        return stack.isEmpty();

    }

    public static void main(String[] args) {
        // Stack<Integer> stack = new Stack<>();
        // System.out.println(stack.peek());//栈不能为空
    }
}
